import { proxy, subscribe } from 'valtio'
import type { ModuleProps } from '@/store/Schema'

export interface PathMapItem {
  path: string // 路径
  formPropsConfig?: ModuleProps
  libraryName?: string // 包名称
  moduleName: string // 模块名称
  // 为什么不把props添加进来，由于props 也有 node 节点去渲染
}

export type ComponentPath = Record<string, PathMapItem>

export const componentPathState: { componentPath: ComponentPath } = proxy(
  JSON.parse(localStorage.getItem('componentPath') as any) || {
    componentPath: {},
  },
)

subscribe(componentPathState, () => {
  localStorage.setItem('componentPath', JSON.stringify(componentPathState))
})
